關機重開後,
啟動 XAMPP 後發現 MySQL 無法啟動...
從XAMPP的訊息看不出什麼...
直接去xampp的資料夾執行mysql_start.batC:\xampp\mysql_start.bat
發現執行失敗
接著去C:\xampp\mysql\data\mysql_error.log
發現已下錯誤
(PS: 出現錯誤1的LOG一開始沒想到要沒保存下來,所以以下是中途的備份)
2022-02-27 16:21:02 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2022-02-27 16:21:02 0 [Note] InnoDB: Uses event mutexes
2022-02-27 16:21:02 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-02-27 16:21:02 0 [Note] InnoDB: Number of pools: 1
2022-02-27 16:21:02 0 [Note] InnoDB: Using SSE2 crc32 instructions
2022-02-27 16:21:02 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2022-02-27 16:21:02 0 [Note] InnoDB: Completed initialization of buffer pool
2022-02-27 16:21:02 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2022-02-27 16:21:02 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-02-27 16:21:02 0 [Note] InnoDB: Setting file '\xampp\mysql\data\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-02-27 16:21:02 0 [Note] InnoDB: File '\xampp\mysql\data\ibtmp1' size is now 12 MB.
2022-02-27 16:21:02 0 [Note] InnoDB: Waiting for purge to start
2022-02-27 16:21:02 0 [Note] InnoDB: 10.4.21 started; log sequence number 47646; transaction id 8
2022-02-27 16:21:02 0 [Note] InnoDB: Loading buffer pool(s) from C:\xampp\mysql\data\ib_buffer_pool
2022-02-27 16:21:02 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-02-27 16:21:02 0 [Note] InnoDB: Buffer pool(s) load completed at 220227 16:21:02
2022-02-27 16:21:02 0 [Note] Server socket created on IP: '::'.
2022-02-27 16:21:02 0 [ERROR] mysqld: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
2022-02-27 16:21:02 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
2022-02-27 16:21:02 0 [ERROR] Aborting
以下是我的修補方式提供大家參考
錯誤1:Using unique option prefix 'key_buffer' is error-prone and can break in the future. Please use the full name 'key_buffer_size' instead.
修改方式如下:
錯誤2:[ERROR] mysqld: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
[ERROR] Fatal error: Can't open and lock privilege tables: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
參考一些網路文章幾乎都是要透過myisamchk修正,
但我卻會出現 XXX is not a MyISAM-table 的錯誤訊息,
在bin資料夾發現aria_chk.exe
於是兩隻都拿來試試看。
不知為啥aria_chk網路上幾乎沒啥資料...
如果有更好的參數使用建議的話歡迎告知
執行以下兩條指令
ps. 如果錯誤訊息不是.\mysql\db,自行修正成自己的路徑
C:\xampp\mysql\bin\myisamchk -c -r C:\xampp\mysql\data\mysql\db*
C:\xampp\mysql\bin\aria_chk -c -r -n C:\xampp\mysql\data\mysql\db*
接著發現有以下錯誤
myisamchk: error: 'C:\xampp\mysql\data\mysql\db.frm' is not a MyISAM-table
myisamchk: error: 'C:\xampp\mysql\data\mysql\db.MAD' is not a MyISAM-table
myisamchk: error: 'C:\xampp\mysql\data\mysql\db.MAI' is not a MyISAM-table
aria_chk: Got error 'Can't find file' when trying to use aria control file '.\aria_log_control'
aria_chk: error: 'C:\xampp\mysql\data\mysql\db.frm' is not a Aria table
aria_chk: error: 'C:\xampp\mysql\data\mysql\db.MAD' is not a Aria table
aria_chk: Index is corrupted
aria_chk: error: 'C:\xampp\mysql\data\mysql\db.MAI' doesn't have a correct index definition. You need to recreate it before you can do a repair
拜google後發現這篇文章建議直接用備份取代
因為不是我專案的資料表,
直接取代比較快
將C:\xampp\mysql\backup\mysql\db.*
複製到 C:\xampp\mysql\data\mysql\db.*
直接取代
重啟後就成功了
最後,
如果想要全部資料庫的資料表都跑過一次,
提供以下批次檔,
有需要的話自行調整路徑
@echo off
set data=C:\xampp\mysql\data
set bin=C:\xampp\mysql\bin
%bin%\myisamchk -c -r %data%\*
%bin%\aria_chk -r %data%\*
for /d %%i in (./data/*) do (
%bin%\myisamchk -c -r %data%\%%i\*
%bin%\aria_chk -c -r -n %data%\%%i\*
)